﻿<%@ WebHandler Language="C#" Class="detail" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using Newtonsoft.Json.Linq;
using System.Collections;

public class detail : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        var _hid=HttpContext.Current.Request.Params["hid"];

        int hid =Convert.ToInt16(_hid);

        if (string.IsNullOrEmpty(_hid))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }

        var code = 1;
        var msg = "商品详情";
        var time = DateTime.Now;

        using (Entities bll = new Entities())
        {

            var x = bll.S_Hotel.FirstOrDefault(p => p.GID == hid && p.GIState== true);

            if (x != null)
            {
                var GetImgs = methods.GetImgs(x.GImg);


                //新建一个JArray对象，可以理解成json对象中 value 位置的数组对象 ->  []

                var room = bll.S_Room.Where(p => p.SCCLASSID == x.GID);

                ArrayList sku_price = new ArrayList();

                foreach (var item in room)
                { 
                var myImg = methods.GetImgs(item.RImg);
                var sku = new
                {
                    id=item.RID,
                  
                    RPriceYJ=item.RPriceYJ,                  
                    RPriceSC=item.RPriceSC,
                    RPriceVIP=item.RPriceVIP,

                    title=item.RName,
                    status="up",
                    //int=item.
                    myImg,
      

                    sn=""
                };

                sku_price.Add(sku);
                        }

                Uri uri = HttpContext.Current.Request.Url;
                String host = uri.Scheme + Uri.SchemeDelimiter + uri.Host + ":" + uri.Port;
                var data = new
                {
                    is_sku=0,
                    sku_price,
                    stock=x.GCounts,   //库存
                    id = x.GID,
                    title=x.GName,
                    content =x.GContent.Replace("src=\"/upload/","src=\""+host+"/upload/"),
                    l = x.GName,
                    x.SCCLASSID,
                    images=GetImgs,
                    image =GetImgs[0].Replace("Up","upload"),
                    original_price= x.GPriceYJ,
                    price = x.GPrice,
                    intr=x.G_Introduce,
                    x.GSort,
                    x.Gtel,
                    x.Glatitude,
                    x.Glongitude,
                    x.GRule
                };

                context.Response.Write(JsonConvert.SerializeObject(new { code,msg,time,data}));
            }
        }

        HttpContext.Current.Response.End();
        //context.Response.Write("Hello World");

    }





    public bool IsReusable {
        get {
            return false;
        }
    }

}